package tt.dz.mvc.controller.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.base.JsonForList;
import tt.dz.entity.base.OmsOrderThirdSet;
import tt.dz.service.base.OrderThirdSetService;
import tt.dz.util.ActionUtils;

/**
 * 
 * @author huanghao
 *
 */
@Controller
@RequestMapping("orderThirdSetApi")
public class OrderThirdSetAction extends BaseAction
{
	@Autowired
	private OrderThirdSetService orderThirdSetServiceImpl;
	@RequestMapping(value="add",method=RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> add(HttpServletRequest request, HttpServletResponse response)
	{
		return orderThirdSetServiceImpl.add(this.getObjFromRequest(request,true,false));
	}
	
	@RequestMapping(value="update/{order_no}",method=RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> updateOperMerchant(@PathVariable(value="order_no") String order_no,
			HttpServletRequest request, HttpServletResponse response)
	{
		OmsOrderThirdSet orderSet = this.getObjFromRequest(request,false,false);
		if (StringUtils.isNotEmpty(order_no))
		{
			orderSet.setOrder_no(order_no);
		}
		return orderThirdSetServiceImpl.update(orderSet);
	}
	
	@RequestMapping(value="delete/{order_no}",method=RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> deleteOperMerchant(@PathVariable(value="order_no") String order_no,
			HttpServletRequest request, HttpServletResponse response)
	{
		return orderThirdSetServiceImpl.delete(order_no);
	}
	
	@RequestMapping(value="findAllOrPage",method=RequestMethod.GET)
	@ResponseBody
	public JsonForList<?> findAllOrPage(HttpServletRequest request, HttpServletResponse response)
	{
		return orderThirdSetServiceImpl.findPageObjs(this.buildQueryParam(request, true), this.getObjFromRequest(request,false,true));
	}
	
	@RequestMapping(value="findObj/{order_no}",method=RequestMethod.GET)
	@ResponseBody
	public JsonCommon<?> findObj(@PathVariable(value="order_no") String order_no,
			HttpServletRequest request, HttpServletResponse response)
	{
		return orderThirdSetServiceImpl.findById(order_no);
	}
	
	private OmsOrderThirdSet getObjFromRequest(HttpServletRequest request,boolean isCreate,boolean isFind)
	{
		String loginUserId = this.getLoginUserId(request);
		return ActionUtils.getParamInstance(OmsOrderThirdSet.class, ActionUtils.getParameterMap(request),loginUserId,isCreate,isFind);
	}
}
